
import { DataSource } from "@/services/data-source";
import { getToken } from "@/utils";
import { invoke } from '@tauri-apps/api/core';
import { ConnectorDataSource } from "@/services/connector";
import { dsFind } from "../datasource";
import { MODEL_CLASS_IDENTIFIER } from "@/services/constants";
import { ComparsionOperator } from "../types";

export interface OllamaModel {

}


///
export const modelOllamaGetModels = async (): Promise<Array<any>> => {

    let modelProvider = 'ollama';

    //
    let { total, data: models } = await dsFind(0, MODEL_CLASS_IDENTIFIER, {
        attributes: [
            {
                name: 'provider_identifier',
                operator: ComparsionOperator.Equal,
                value: modelProvider
            }
        ]
    });

    // 
    let response: Array<any> = await invoke('plugin:mg-platform|ollama_list', {
        modelProvider: modelProvider,
    });
    console.log(response);

    return models.map((item, index) => {
        let installed = response.filter(v => v.name === item.name).length > 0;

        return {
            ...item,
            installed,
        }
    });
}



///
export const modelOllamaPullModel = async (model: string): Promise<Array<any>> => {

    let modelProvider = 'ollama';

    // 
    let response: Array<any> = await invoke('plugin:mg-platform|ollama_pull', {
        modelProvider: modelProvider,
        model: model
    });
    console.log(response);
    return response;
}